$LOAD_PATH.unshift File.join(File.dirname(__FILE__),'../..','ext_pr1/lib')
require 'ext_pr1_v4'

# function returning the min-value of a pair of two int-Values
# min_int :: (val1,val2) ::
#  INT X INT => INT ::::
#
# Examples
#  min_int(10,20) => 10
#  min_int(20,10) => 10
#  min_int(20,20) => 20
#  min_int(-1,10) => -1
#  min_int(10,-1) => -1
#  min_int(0,0) => 0
#  min_int(-2,-1) => -2
#  min_int(-1,-2) => -2
#  min_int("a",1) => ERR
#  min_int(1,"a") => ERR
#  min_int(1.0,1) => ERR
#  min_int(1,1.0) => ERR
#  min_int(1,true) => ERR
#  min_int(false,1) => ERR
def min_int(a,b)
  check_pre((a.int? and b.int?))
  a < b ? a : b
end

# function returing the max-value of a pair of two int-Values
# max_int :: (val1,val2) ::
#  INT X INT => INT ::::
#
# Examples
#  max_int(10,20) => 20
#  max_int(20,10) => 20
#  max_int(20,20) => 20
#  max_int(-1,10) => 10
#  max_int(10,-1) => 10
#  max_int(0,0) => 0
#  max_int(-2,-1) => -1
#  max_int(-1,-2) => -1
#  max_int("a",1) => ERR
#  max_int(1,"a") => ERR
#  max_int(1.0,1) => ERR
#  max_int(1,1.0) => ERR
#  max_int(1,true) => ERR
#  max_int(false,1) => ERR
def max_int(a,b)
  check_pre((a.int? and b.int?))
  a < b ? b : a
end

# function returning true or false if an int-value between two other int-values
# within? :: (val, lower, upper) :: 
#   INT x INT x INT => BOOL :: (lower < upper)
#   
# Examples
# 
#  Values
#  # pos. Intervall
#  within?(4,5,10) = > false
#  within?(5,5,10) = > true
#  within?(6,5,10) = > true
#  within?(9,5,10) = > true
#  within?(10,5,10)  = > true
#  within?(11,5,10) = > false
#  # neg. Intervall
#  within?(-11,-10,-5)  = > false
#  within?(-10,-10,-5) = > true
#  within?(-9,-10,-5) = > true
#  within?(-6,-10,-5)  = > true
#  within?(-5,-10,-5)  = > true
#  within?(-4,-10,-5)  = > false
#  # mixed Intervall
#  within?(-1,-10,10)  = > true
#  within?(1,-10,10)  = > true
#  within?(-11,-10,10)  = > false
#  within?(11,-10,10)  = > false
#  
#
#  # intervall errors lower bigger than upper
#  within?(6,10,5) = > ERR 
#  within?(-6,-5,-10) = > ERR 
#  within?(-6,-6,-6) => ERR
#  within?(6,6,6) => ERR
#  Types
#  within?(0,"a",12) = > ERR 
#  within?("a",10,12) => ERR 
#  within?(0,10,"a") = > ERR 
#  within?(15.0,14,16) = > ERR 
#  within?(15,14.0,16) = > ERR 
#  within?(15,14,16.0) = > ERR 
#  within?(true,14,16) = > ERR 
#  within?(15,true,16) = > ERR 
#  within?(15,14,true) = > ERR 
#  
#  Arguments
#  within?() => ERR
#  within?(2) => ERR
#  within?(2,3) => ERR 
#  
def within?(val, lower, upper)
   check_pre(( val.int? and lower.int? and upper.int? and (lower<upper)))
   (lower.pred() < val and val < upper.succ())
end